from django.db import models

# Create your models here.
# 会员管理
class Users(models.Model):
	name = models.CharField(max_length=32)
	password = models.CharField(max_length=80,default='1')
	age = models.IntegerField(default=20)
	sex = models.CharField(max_length=1,default='1')
	address = models.CharField(max_length=32,null=True)
	phone = models.CharField(max_length=15,default='1')
	state = models.CharField(max_length=1,default='1')
	pic  = models.CharField(max_length=50,default='/static/public/pics/user.jpg')
	addtime = models.DateField(auto_now_add=True)

# 商品分类
class Types(models.Model):
	name = models.CharField(max_length=50)
	pid = models.IntegerField()
	path = models.CharField(max_length=20)


# 商品管理
class Goods(models.Model):
	typeid = models.ForeignKey(to="Types", to_field="id")
	title = models.CharField(max_length=255)
	price = models.DecimalField(max_digits=8, decimal_places=2)
	storage = models.IntegerField()
	pic = models.CharField(max_length=50)
	info = models.TextField()
	status = models.IntegerField()
	addtime = models.DateField(auto_now_add=True)

# 订单表
class Order(models.Model):
	uid = models.ForeignKey('Users',to_field="id")
	addname = models.CharField(max_length=50)
	address = models.CharField(max_length=255)
	addphone = models.CharField(max_length=11)
	addcode = models.CharField(max_length=10)
	totalprice = models.FloatField()
	totalnum = models.IntegerField()
	# 1 未付款 2已付款,待发货,3已发货,待收货,4已完成,5已取消
	status = models.IntegerField()
	addtime = models.DateTimeField(auto_now_add=True)

# 订单详情
class OrderInfo(models.Model):
	orderid = models.ForeignKey('Order',to_field="id")
	gid =  models.ForeignKey('Goods',to_field="id")
	num = models.IntegerField()
	price = models.FloatField()

class Map(models.Model):
	pic = models.CharField(max_length=50)